Add tests for all targets without names
authordinesh <dsdiscoverdinesh@gmail.com>
Tue, 30 Jun 2015 19:44:46 +0000 (01:14 +0530)
committerdinesh <dsdiscoverdinesh@gmail.com>
Thu, 2 Jul 2015 17:00:55 +0000 (22:30 +0530)
tests/test_cargo_test.rs

index 3e34f7c9c19e7a6addfde28dce1c934106e93738..f9473fd20aaebdb8db7a77f6f8b526c7aac56618 100644 (file)
@@ -721,6 +721,172 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
 ", compiling = COMPILING, running = RUNNING, dir = p.url())));
 });
 
+test!(bin_without_name {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "syntax"
+            version = "0.0.1"
+            authors = []
+
+            [lib]
+            test = false
+            doctest = false
+
+            [[bin]]
+            path = "src/main.rs"
+        "#)
+        .file("src/lib.rs", "
+            pub fn foo() {}
+        ")
+        .file("src/main.rs", "
+            extern crate syntax;
+
+            fn main() {}
+
+            #[test]
+            fn test() { syntax::foo() }
+        ");
+
+    assert_that(p.cargo_process("test"),
+                execs().with_status(101)
+                       .with_stderr(&format!("\
+failed to parse manifest at `[..]`
+
+Caused by:
+  binary target bin.name is required")));
+});
+
+test!(bench_without_name {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "syntax"
+            version = "0.0.1"
+            authors = []
+
+            [lib]
+            test = false
+            doctest = false
+
+            [[bench]]
+            path = "src/bench.rs"
+        "#)
+        .file("src/lib.rs", "
+            pub fn foo() {}
+        ")
+        .file("src/main.rs", "
+            extern crate syntax;
+
+            fn main() {}
+
+            #[test]
+            fn test() { syntax::foo() }
+        ")
+        .file("src/bench.rs", "
+            #![feature(test)]
+            extern crate syntax;
+            extern crate test;
+
+            #[bench]
+            fn external_bench(_b: &mut test::Bencher) {}
+        ");
+
+    assert_that(p.cargo_process("test"),
+                execs().with_status(101)
+                       .with_stderr(&format!("\
+failed to parse manifest at `[..]`
+
+Caused by:
+  bench target bench.name is required")));
+});
+
+test!(test_without_name {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "syntax"
+            version = "0.0.1"
+            authors = []
+
+            [lib]
+            test = false
+            doctest = false
+
+            [[test]]
+            path = "src/test.rs"
+        "#)
+        .file("src/lib.rs", r#"
+            pub fn foo() {}
+            pub fn get_hello() -> &'static str { "Hello" }
+        "#)
+        .file("src/main.rs", "
+            extern crate syntax;
+
+            fn main() {}
+
+            #[test]
+            fn test() { syntax::foo() }
+        ")
+        .file("src/test.rs", r#"
+            extern crate syntax;
+
+            #[test]
+            fn external_test() { assert_eq!(syntax::get_hello(), "Hello") }
+        "#);
+
+    assert_that(p.cargo_process("test"),
+                execs().with_status(101)
+                       .with_stderr(&format!("\
+failed to parse manifest at `[..]`
+
+Caused by:
+  test target test.name is required")));
+});
+
+test!(example_without_name {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "syntax"
+            version = "0.0.1"
+            authors = []
+
+            [lib]
+            test = false
+            doctest = false
+
+            [[example]]
+            path = "examples/example.rs"
+        "#)
+        .file("src/lib.rs", "
+            pub fn foo() {}
+        ")
+        .file("src/main.rs", "
+            extern crate syntax;
+
+            fn main() {}
+
+            #[test]
+            fn test() { syntax::foo() }
+        ")
+        .file("examples/example.rs", r#"
+            extern crate syntax;
+
+            fn main() {
+                println!("example1");
+            }
+        "#);
+
+    assert_that(p.cargo_process("test"),
+                execs().with_status(101)
+                       .with_stderr(&format!("\
+failed to parse manifest at `[..]`
+
+Caused by:
+  example target example.name is required")));
+});
+
 test!(bin_there_for_integration {
     let p = project("foo")
         .file("Cargo.toml", r#"